package cn.autoOffice.service.impl;
/*
 *功能说明：文件管理业务实现类
 *@author 皮永浪
 *@Date 2023/3/27 14:08
 */

import cn.autoOffice.bean.pojo.DocumentManagement;
import cn.autoOffice.mapper.DocumentManagementMapper;
import cn.autoOffice.service.DocumentManagementService;
import cn.autoOffice.service.RedisService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DocumentManagementServiceImpl implements DocumentManagementService {

    @Autowired
    @Resource
    private DocumentManagementMapper documentManagementMapper;

    @Autowired
    public RedisService redisService;

    public Integer countFile(){
        String count = redisService.getValue("allFileCount");
        if (count != null && !"".equals(count)){
            return Integer.parseInt(count);
        } else {
            Integer integer = documentManagementMapper.countFile();
            redisService.putValue("allFileCount",integer);
            return integer;
        }
    }

    public List<DocumentManagement> getDocumentAll(){
        return documentManagementMapper.getDocumentAll();
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public Integer addDocument(DocumentManagement documentManagement){
        Integer integer = documentManagementMapper.addDocument(documentManagement);
        return integer;
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public DocumentManagement getDocument(String documentName){
        DocumentManagement document = documentManagementMapper.getDocument(documentName);
        return document;
    }
}
